/* eslint-disable */
import React, { useState, useImperativeHandle, forwardRef } from 'react';
import { Table, Divider, Input, DatePicker, Button, Row, Col, } from 'antd';
import moment from 'moment';
import { emptyText, debounce } from '../../../utils/commonUtil';

const { TextArea } = Input;

let MedialitigationMaintenance = (props, ref) => {

  const { medialitigationData, onAdd, onCancel, useSpinFlag, basicInformationData } = props;
  const [medList, setMedList] = useState({ ...medialitigationData });

  useImperativeHandle(ref, () => ({
    medList
  }));

  const onChange = (values, index, key, obj) => {
    medList[obj][index][key] = values
    if (!medList[obj][index].masterDataCode) medList[obj][index].masterDataCode = basicInformationData.masterDataCode
    setMedList({ ...medList })
  }

  const HearingAnnouncement = [
    {
      title: '案号', dataIndex: 'caseNo', key: 'caseNo',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "caseNo", "announcementList") }}
          style={{
            color: record.caseNoFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '标题', dataIndex: 'title', key: 'title',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "title", "announcementList") }}
          style={{
            color: record.titleFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '内容', dataIndex: 'body', key: 'body',
      render: (text, record, index) => (
        <TextArea autoSize={{ minRows: 1, maxRows: 1 }} value={text} onChange={(e) => { onChange(e.target.value, index, "body", "announcementList") }}
          style={{
            color: record.bodyFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '法院', dataIndex: 'court', key: 'court',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "court", "announcementList") }}
          style={{
            color: record.courtFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '法庭', dataIndex: 'courtRoom', key: 'courtRoom',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "courtRoom", "announcementList") }}
          style={{
            color: record.courtRoomFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '开庭时间', dataIndex: 'sortTime', key: 'sortTime',
      render: (text, record, index) => (
        <DatePicker value={text ? moment(text) : ""} onChange={(data, dateString) => { onChange(dateString, index, "sortTime", "announcementList") }}
          style={{
            width: "100%", color: record.sortTimeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '操作', key: 'operate', width: 80,
      render: (text, record, index) => (
        <Button type="link" onClick={() => { onDelete("announcementList", index) }} size="small">删除</Button>
      ),
    },
  ];
  const CourtAnnouncement = [
    {
      title: '案号', dataIndex: 'caseNo', key: 'caseNo',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "caseNo", "announcementCourtList") }}
          style={{
            color: record.caseNoFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '标题', dataIndex: 'title', key: 'title',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "title", "announcementCourtList") }}
          style={{
            color: record.titleFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '内容', dataIndex: 'body', key: 'body',
      render: (text, record, index) => (
        <TextArea autoSize={{ minRows: 1, maxRows: 1 }} value={text} onChange={(e) => { onChange(e.target.value, index, "body", "announcementList") }}
          style={{
            color: record.bodyFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '法院名称', dataIndex: 'court', key: 'court',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "court", "announcementCourtList") }}
          style={{
            color: record.courtFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '立案时间', dataIndex: 'sortTime', key: 'sortTime',
      render: (text, record, index) => (
        <DatePicker value={text ? moment(text) : ""} onChange={(data, dateString) => { onChange(dateString, index, "sortTime", "announcementCourtList") }}
          style={{
            width: "100%", color: record.sortTimeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '操作', key: 'operate', width: 80,
      render: (text, record, index) => (
        <Button type="link" onClick={() => { onDelete("announcementCourtList", index) }} size="small">删除</Button>
      ),
    },
  ];
  const RefereeDocuments = [
    {
      title: '案号', dataIndex: 'caseNo', key: 'caseNo',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "caseNo", "announcementRefereeList") }}
          style={{
            color: record.caseNoFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '标题', dataIndex: 'title', key: 'title',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "title", "announcementRefereeList") }}
          style={{
            color: record.titleFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '内容', dataIndex: 'body', key: 'body',
      render: (text, record, index) => (
        <TextArea autoSize={{ minRows: 1, maxRows: 1 }} value={text} onChange={(e) => { onChange(e.target.value, index, "body", "announcementList") }}
          style={{
            color: record.bodyFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '法院', dataIndex: 'court', key: 'court',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "court", "announcementRefereeList") }}
          style={{
            color: record.courtFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '判决结果', dataIndex: 'judgeResult', key: 'judgeResult',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "judgeResult", "announcementRefereeList") }}
          style={{
            color: record.judgeResultFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '审结日期', dataIndex: 'sortTime', key: 'sortTime',
      render: (text, record, index) => (
        <DatePicker value={text ? moment(text) : ""} onChange={(data, dateString) => { onChange(dateString, index, "sortTime", "announcementRefereeList") }}
          style={{
            width: "100%", color: record.sortTimeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '操作', key: 'operate', width: 80,
      render: (text, record, index) => (
        <Button type="link" onClick={() => { onDelete("announcementRefereeList", index) }} size="small">删除</Button>
      ),
    },
  ];
  const PerformAnnouncement = [
    {
      title: '案号', dataIndex: 'caseCode', key: 'caseCode',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "caseCode", "announcementPunishedList") }}
          style={{
            color: record.caseCodeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '被执行人姓名/名称', dataIndex: 'nameClean', key: 'nameClean',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "nameClean", "announcementPunishedList") }}
          style={{
            color: record.nameCleanFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '被执行人类型', dataIndex: 'type', key: 'type',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "type", "announcementPunishedList") }}
          style={{
            color: record.typeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '身份证号码/企业注册号', dataIndex: 'cardNumber', key: 'cardNumber',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "cardNumber", "announcementPunishedList") }}
          style={{
            color: record.cardNumberFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '案件状态', dataIndex: 'caseState', key: 'caseState',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "caseState", "announcementPunishedList") }}
          style={{
            color: record.caseStateFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '执行标的（元）', dataIndex: 'execMoney', key: 'execMoney',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "execMoney", "announcementPunishedList") }}
          style={{
            color: record.execMoneyFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '立案时间', dataIndex: 'caseTime', key: 'caseTime',
      render: (text, record, index) => (
        <DatePicker value={text ? moment(text) : ""} onChange={(data, dateString) => { onChange(dateString, index, "caseTime", "announcementRefereeList") }}
          style={{
            width: "100%", color: record.caseTimeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '执行法院', dataIndex: 'courtName', key: 'courtName',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "courtName", "announcementPunishedList") }}
          style={{
            color: record.courtNameFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '操作', key: 'operate', width: 80,
      render: (text, record, index) => (
        <Button type="link" onClick={() => { onDelete("announcementPunishedList", index) }} size="small">删除</Button>
      ),
    },
  ];
  const newsMedia = [
    {
      title: '标题', dataIndex: 'title', key: 'title',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "title", "announcementNewsList") }}
          style={{
            color: record.titleFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '标签', dataIndex: 'tags', key: 'tags',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "tags", "announcementNewsList") }}
          style={{
            color: record.tagsFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '摘要', dataIndex: 'summary', key: 'summary',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "summary", "announcementNewsList") }}
          style={{
            color: record.summaryFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '内容', dataIndex: 'body', key: 'body',
      render: (text, record, index) => (
        <TextArea autoSize={{ minRows: 1, maxRows: 1 }} value={text} onChange={(e) => { onChange(e.target.value, index, "body", "announcementList") }}
          style={{
            color: record.bodyFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '当事人', dataIndex: 'name', key: 'name',
      render: (text, record, index) => (
        <Input value={text} onChange={(e) => { onChange(e.target.value, index, "name", "announcementNewsList") }}
          style={{
            color: record.nameFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },
    {
      title: '发布时间', dataIndex: 'sortTime', key: 'sortTime',
      render: (text, record, index) => (
        <DatePicker value={text ? moment(text) : ""} onChange={(data, dateString) => { onChange(dateString, index, "sortTime", "announcementNewsList") }}
          style={{
            width: "100%", color: record.sortTimeFlag == 1 ?
              "#e64552" : ""
          }} />
      ),
    },

    {
      title: '操作', key: 'operate', width: 80,
      render: (text, record, index) => (
        <Button type="link" onClick={() => { onDelete("announcementNewsList", index) }} size="small">删除</Button>
      ),
    },
  ];

  const addSave = (obj) => {
    medList[obj] ? medList[obj].push({ key: +new Date() + '' }) : medList[obj] = [{ key: +new Date() + '' }]
    setMedList(JSON.parse(JSON.stringify(medList)))
  }

  const onDelete = (obj, index) => {
    let data = medList[obj].splice(index, 1)
    setMedList(JSON.parse(JSON.stringify(medList)))
  }

  const debounceAddFun = debounce(onAdd, 1000)

  return (
    <div>
      <Row>
        <Col span={24} align="right">
          <Button onClick={() => onCancel()}>返回</Button>
          <Button style={{ marginLeft: '15px' }} onClick={() => { useSpinFlag(true); debounceAddFun() }}>保存</Button>
        </Col>
      </Row>
      <Divider orientation="left">开庭公告</Divider>
      <Table
        size="small"
        columns={HearingAnnouncement}
        dataSource={medList.announcementList}
        pagination={false}
        scroll={{ y: 500 }}
        rowKey={record => record.id ? record.id : record.key}
        style={{ marginBottom: "32px" }}
        locale={{ emptyText }}
      />
      <Row>
        <Col span={24} style={{ marginBottom: "32px" }}>
          <Button type="dashed" block onClick={() => addSave("announcementList")}>新增行</Button>
        </Col>
      </Row>
      <Divider orientation="left">法院公告</Divider>
      <Table
        size="small"
        columns={CourtAnnouncement}
        dataSource={medList.announcementCourtList}
        pagination={false}
        scroll={{ y: 500 }}
        rowKey={record => record.id ? record.id : record.key}
        style={{ marginBottom: "32px" }}
        locale={{ emptyText }}
      />
      <Row>
        <Col span={24} style={{ marginBottom: "32px" }}>
          <Button type="dashed" block onClick={() => addSave("announcementCourtList")}>新增行</Button>
        </Col>
      </Row>
      <Divider orientation="left">裁判文书</Divider>
      <Table
        size="small"
        columns={RefereeDocuments}
        dataSource={medList.announcementRefereeList}
        pagination={false}
        scroll={{ y: 500 }}
        rowKey={record => record.id ? record.id : record.key}
        style={{ marginBottom: "32px" }}
        locale={{ emptyText }}
      />
      <Row>
        <Col span={24} style={{ marginBottom: "32px" }}>
          <Button type="dashed" block onClick={() => addSave("announcementRefereeList")}>新增行</Button>
        </Col>
      </Row>
      <Divider orientation="left">执行公告</Divider>
      <Table
        size="small"
        columns={PerformAnnouncement}
        dataSource={medList.announcementPunishedList}
        pagination={false}
        scroll={{ y: 500 }}
        rowKey={record => record.id ? record.id : record.key}
        style={{ marginBottom: "32px" }}
        locale={{ emptyText }}
      />
      <Row>
        <Col span={24} style={{ marginBottom: "32px" }}>
          <Button type="dashed" block onClick={() => addSave("announcementPunishedList")}>新增行</Button>
        </Col>
      </Row>
      <Divider orientation="left">新闻媒体</Divider>
      <Table
        size="small"
        columns={newsMedia}
        dataSource={medList.announcementNewsList}
        pagination={false}
        scroll={{ y: 500 }}
        rowKey={record => record.id ? record.id : record.key}
        style={{ marginBottom: "32px" }}
        locale={{ emptyText }}
      />
      <Row>
        <Col span={24} style={{ marginBottom: "200px" }}>
          <Button type="dashed" block onClick={() => addSave("announcementNewsList")}>新增行</Button>
        </Col>
      </Row>
    </div>
  );
}

MedialitigationMaintenance = forwardRef(MedialitigationMaintenance)

export default MedialitigationMaintenance;
